import collections
from typing import List


class Solution:
    def distinctNumbers(self, nums: List[int], k: int) -> List[int]:
        ans = []
        count = collections.Counter(nums[:k])
        for i in range(len(nums) - k):
            ans.append(len(count))
            count[nums[i + k]] += 1
            count[nums[i]] -= 1
            if count[nums[i]] == 0:
                count.pop(nums[i])
        ans.append(len(count))
        return ans


if __name__ == "__main__":
    print(Solution().distinctNumbers(nums=[1, 2, 3, 2, 2, 1, 3], k=3))  # [3,2,2,2,3]
    print(Solution().distinctNumbers(nums=[1, 1, 1, 1, 2, 3, 4], k=4))  # [1,2,3,4]
